<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2023/5/11
  Time: 10:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%String path = request.getContextPath()+"/";%>
<html>
<head>
    <base href="<%=path%>">
    <title>用户编辑</title>
    <script type="text/javascript" src="webjars/jquery/3.2.0/jquery.js"></script>
</head>
<body>
<form action="" method="post" id="deptForm">
    <input type="hidden" name="id" value="${user.id}">
    用户名称：<input type="text" name="userName" value="${user.userName}">
        <input type="button" value="保存" onclick="save();">
</form>
</body>
<script>
    function save(){
        // 将form表单中的数据发请求到后端
       var data = $("#deptForm").serialize();
        $.ajax({
            url:'user/save',
            type:'post',
            data:data,
            success:function(ret){
                if(ret){
                    alert('操作成功')
                    document.location.href="user/list"
                }else{
                    alert('操作失败')
                }
            }
        })

    }
</script>
</html>
